// @ts-ignore
import {differenceInDays, differenceInYears, format, parseISO} from 'date-fns';

export function getTimeTick(): number {
    const timestamp = Date.now();
    const dateString = format(timestamp, 'yyyy-MM-dd HH:mm:ss');
    const date = parseISO(dateString);
    return date.getTime();
}

export function timeStrAsTick(dateString: string): number {
    const date = parseISO(dateString);
    return date.getTime();
}


export function tickAsTime(timestampSeconds: number): Date {
    return new Date(timestampSeconds * 1000);
}

export function tickAsTimeString(timestamp: number, _format: string = 'yyyy-MM-dd HH:mm:ss'): string {
    const date = new Date(timestamp);
    return format(date, _format);
}

export function dataAsString(date:Date, _format: string = 'yyyy-MM-dd HH:mm:ss'): string {
    return format(date, _format);
}



export function diffDay(date1: Date, date2: Date): number {
    return differenceInDays(date1, date2)
}

export function diffDYear(tick: number, tick2: number): number {
    const dateString = format(tick, 'yyyy-MM-dd HH:mm:ss');
    const dateString2 = format(tick2, 'yyyy-MM-dd HH:mm:ss');
    const date1 = parseISO(dateString);
    const date2 = parseISO(dateString2);
    return differenceInYears(date1, date2)
}

